package model

import (
	"qabx.net/safe-app-center/pkg/utils"
	"time"
)

/*

CREATE TABLE "public"."tbl_app_analyze" (
  "app_id" int4,
  "start_time" timestamp(6),
  "end_time" timestamp(6),
  "create_time" timestamp(6),
  "update_time" timestamp(6),
  "is_del" int2,
  "device_id" int4
)
*/

type TblAppAnalyze struct {
	AppId      int    `json:"app_id"`
	StartTime  string `json:"start_time"`
	EndTime    string `json:"end_time"`
	CreateTime string `json:"create_time"`
	UpdateTime string `json:"update_time"`
	IsDel      int    `json:"is_del"`
	DeviceId   int    `json:"device_id"`
}

func (s *TblAppAnalyze) AddAppAnalyzeLog() error {
	dbClient, _ := utils.GetDbClient()

	s.CreateTime = time.Now().Format("2006-01-02 15:04:05")
	s.UpdateTime = time.Now().Format("2006-01-02 15:04:05")
	s.IsDel = 0
	dbClient.InsertParam = utils.InsertParam{
		Resource: s,
		Table:    "tbl_app_analyze",
	}
	_, err := dbClient.Insert()
	if err != nil {
		return err
	}
	return err

}
